# -*- coding: utf-8 -*-
# owner: shenyi

from typing import List, Optional, Literal
from pydantic import BaseModel, Field


class Disk(BaseModel):
    size: int = Field(..., description="Disk size in GiB")
    type: str = Field(..., description="Disk category, e.g., cloud_essd")
    device_name: str = Field(..., description="Device name, e.g., /dev/xvdb")


class CreateInstanceRequest(BaseModel):
    host_name: str = Field(..., description="Instance host name")
    instance_type: str = Field(..., description="Instance type, e.g., ecs.g6.large")
    image_id: str = Field(..., description="Image ID")
    data_disk: List[Disk] = Field(default_factory=list, description="List of data disks")
    launch_template_id: str = Field(default="", description="Launch template ID")
    launch_template_version: str = Field(default="", description="Launch template version")
    internet_max_bandwidth_out: int = Field(default=0, description="Public network outbound bandwidth (Mbps)")
    vpc_id: Optional[str] = Field(default=None, description="VPC ID")
    subnet_id: Optional[str] = Field(default=None, description="Subnet (vSwitch) ID")
    password_inherit: bool = Field(default=True, description="Inherit password from image")
    key_pair_name: Optional[str] = Field(default=None, description="SSH key pair name")


class DeleteInstanceRequest(BaseModel):
    instance_id: str = Field(..., description="Instance ID to delete")
    zone_id: Optional[str] = Field(default=None, description="Zone ID")


class QueryInstanceRequest(BaseModel):
    instance_ids: Optional[List[str]] = Field(None, description="要查询的实例 ID 列表")
    instance_name: Optional[str] = Field(None, description="实例名称（模糊匹配）")
    zone_id: Optional[str] = Field(None, description="可用区 ID")


class InstanceTypeRequest(BaseModel):
    zone_id: str = Field(..., description="Zone ID")
    mini_cpu_core_count: int = Field(default=0, description="Minimum CPU core count")
    mini_memory_size: int = Field(default=0, description="Minimum memory size in GiB")
    cpu_architecture: Literal["x86", "arm"] = Field(default="x86", description="CPU architecture: x86 or arm")
    instance_type_families: str = Field(default="ecs.g6", description="Comma-separated instance type families, e.g., ecs.g6,ecs.c6")
    exclude_families: str = Field(default="", description="Comma-separated families to exclude")
    instance_category: Optional[str] = Field(default=None, description="Instance category")


class AvailableInstanceTypeRequest(BaseModel):
    zone_id: str = Field(..., description="Zone ID")
    disk_category: Optional[str] = Field(default=None, description="System/data disk category, e.g., cloud_essd")